#include "RockmanFactory.h"
#include "..\Components\AnimationComponent.h"
#include "..\Components\PlayerHealthComponent.h"
#include "..\Components\PhysicsComponent.h"
#include "..\Components\SensorComponent.h"
#include "..\Components\VisualComponent.h"
#include "..\Components\PlayerControllerComponent.h"
#include "..\Components\FollowCamComponent.h"
#include "..\Components\FlashComponent.h"
#include "..\Components\PlayerDeathComponent.h"
#include "..\Managers\PhysicsManager.h"
#include <functional>

RockmanFactory::RockmanFactory(void){}
RockmanFactory::~RockmanFactory(void){}

GameObject* RockmanFactory::createPlayer(const vn::Vector2& p_position)
{
	GameObject* go = new GameObject("player", nullptr, nullptr);
	IComponent* ic = new VisualComponent(1, "rockman_main", 1.0f);
	go->addComponent(ic);
	PlayerControllerComponent* pcc = new PlayerControllerComponent;
	go->addComponent(pcc);
	ic = new PhysicsComponent(b2_dynamicBody, b2Vec2(22.0f, 22.0f), b2Vec2(p_position.x, p_position.y), FIXT_ID_PLAYER, COLLF_PLAYER, COLLF_WORLD | COLLF_ENEMY_SENSOR);
	static_cast<PhysicsComponent*>(ic)->getBody()->SetFixedRotation(true);
	go->addComponent(ic);
	ic = new AnimationComponent("animations/rockman_main.xml");
	go->addComponent(ic);
	SensorComponent* sc = new SensorComponent(FIXT_ID_PLAYER_SENSOR_GROUND, b2Vec2(18.0f, 5.5f), b2Vec2(0.0f, 10.0f), 0, COLLF_PLAYER_SENSOR, COLLF_WORLD);
	go->addComponent(sc);
	ic = new PlayerHealthComponent(vn::Vector2(20, 20), 0, 50, 3.0f);
	std::function<void()> func = [=] { pcc->die(); };
	static_cast<PlayerHealthComponent*>(ic)->setDeathCallback(func);
	go->addComponent(ic);
	ic = new FollowCamComponent("main");
	go->addComponent(ic);
	ic = new FlashComponent(2000.0f);
	go->addComponent(ic);
	go->initComponents();
	return go;
}